﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace jSLCore.Client.Presentation.BaseControl.Selection
{
    public partial class MultiSelectColumn : DataGridTemplateColumn
    {
        public MultiSelectColumn()
        {
            InitializeComponent();
        }

        private void row_Clicked(object sender, RoutedEventArgs e)
        {
            var element = sender as FrameworkElement;
            if (element != null) InvokeRowSelected(element.DataContext);
        }

        public event EventHandler<RowSelectedEventArgs> RowSelected;
        public event EventHandler<RowSelectedEventArgs> RowUnselected;
        internal event EventHandler CheckBox_Loaded;

        internal void InvokeCheckBoxLoaded(object sender)
        {
            EventHandler handler = CheckBox_Loaded;
            if (handler != null) handler(sender, EventArgs.Empty);
        }

        public void InvokeRowUnselected(object row)
        {
            EventHandler<RowSelectedEventArgs> handler = RowUnselected;
            if (handler != null) handler(this, new RowSelectedEventArgs(row));
        }

        public void InvokeRowSelected(object row)
        {
            EventHandler<RowSelectedEventArgs> handler = RowSelected;
            if (handler != null) handler(this, new RowSelectedEventArgs(row));
        }

        private void row_unClicked(object sender, RoutedEventArgs e)
        {
            var element = sender as FrameworkElement;
            if (element != null) InvokeRowUnselected(element.DataContext);
        }

        private void checkBox_Loaded(object sender, RoutedEventArgs e)
        {
            InvokeCheckBoxLoaded(sender);
        }

        private void checkBox_Layout(object sender, EventArgs e)
        {
            InvokeCheckBoxLoaded(sender);
        }
    }
}
